From: Keir Fraser Date: Mon, 21 Jun 2010 17:35:10 +0000 (+0100) Subject: xl: fix command truncation X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~11899 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=e862bdf68fdc53d9cee4686b579fd8dd8d31ff32;p=xen.git xl: fix command truncation Fix the truncation code so that it always accepts an exact match, even when one command is a prefix of another one. This fixes, e.g., "xl list" Signed-off-by: Tim Deegan --- diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index da00cda663..4d4fb7b330 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -316,18 +316,19 @@ struct cmd_spec *cmdtable_lookup(const char *s) { struct cmd_spec *cmd = NULL; size_t len; - int i; + int i, count = 0; if (!s) return NULL; len = strlen(s); for (i = 0; i < cmdtable_len; i++) { if (!strncmp(s, cmd_table[i].cmd_name, len)) { - if (cmd == NULL) - cmd = &cmd_table[i]; - else - return NULL; + cmd = &cmd_table[i]; + /* Take an exact match, even if it also prefixes another command */ + if (len == strlen(cmd->cmd_name)) + return cmd; + count++; } } - return cmd; + return (count == 1) ? cmd : NULL; }